package com.example.swimmingpool.response;

import com.example.swimmingpool.enums.HttpEnum;
import lombok.Data;

import java.util.ArrayList;

@Data
public class CommonResponse<T> {
    private T data;
    private String msg;
    private Integer code;

    private CommonResponse(T data, String msg, Integer code) {
        this.data = data;
        this.msg = msg;
        this.code = code;
    }

    public static <T> CommonResponse<T> success(T data) {
        return new CommonResponse<>(data, HttpEnum.SUCCESS.getMsg(), HttpEnum.SUCCESS.getCode());
    }

    public static CommonResponse<Object> success() {
        return new CommonResponse<>(new ArrayList<>(), HttpEnum.SUCCESS.getMsg(), HttpEnum.SUCCESS.getCode());
    }

    public static CommonResponse<Object> success(String msg) {
        return new CommonResponse<>(new ArrayList<>(), msg, HttpEnum.SUCCESS.getCode());
    }

    public static <T> CommonResponse<T> success(T data, String msg) {
        return new CommonResponse<>(data, msg, HttpEnum.SUCCESS.getCode());

    }

    public static <T> CommonResponse<T> fail(T data) {
        return new CommonResponse<>(data, HttpEnum.FAILED.getMsg(), HttpEnum.FAILED.getCode());
    }


    public static CommonResponse<Object> fail() {
        return new CommonResponse<>(new ArrayList<>(), HttpEnum.FAILED.getMsg(), HttpEnum.FAILED.getCode());
    }

    public static CommonResponse<Object> fail(String msg) {
        return new CommonResponse<>(new ArrayList<>(), msg, HttpEnum.FAILED.getCode());
    }

    public static <T> CommonResponse<T> fail(T data, String msg) {
        return new CommonResponse<>(data, msg, HttpEnum.FAILED.getCode());


    }


}
